/* * Bluetooh Basic: Stepper Control * Coder - Mayoogh Girish for LED * Modified by Yasir Shafiullah for Stepper * Website - http://bit.do/Avishkar * Download the App : * This program lets you to control a LED on pin 13 of arduino using a bluetooth module */ #include #define txPin 4 // PA0(MISO) transmit signal to the bridge #define rxPin 5 // PA1(SCK) recieves signal from bridge SoftwareSerial mySerial(rxPin,txPin); const int stepPin = 3; const int dirPin = 2; char Incoming_value = 0; //Variable for storing Incoming_value void setup() { mySerial.begin(9600); //Sets the data rate in bits per second (baud) for serial data transmission pinMode(txPin, INPUT); //default tx as input pinMode(stepPin,OUTPUT); pinMode(dirPin,OUTPUT); } void loop() { if(mySerial.available() > 0) { Incoming_value = mySerial.read(); //Read the incoming data and store it into variable Incoming_value mySerial.print(Incoming_value); //Print Value of Incoming_value in Serial monitor mySerial.print("\n"); //New line if(Incoming_value == '2') //Checks whether value of Incoming_value is equal to 2 { digitalWrite(dirPin,LOW); // Enables the motor to move in a particular direction // Makes 200 pulses for making one full cycle rotation for(int x = 0; x < 1000; x++) { digitalWrite(stepPin,HIGH); delay(1); // ms digitalWrite(stepPin,LOW); delay(1); if(Incoming_value == 'B') //Checks whether value of Incoming_value is equal to B { digitalWrite(dirPin,LOW); //If value is B then set dir low and Step low digitalWrite(stepPin,LOW); } else if(Incoming_value == 'I') //Checks whether value of Incoming_value is equal to 0 { digitalWrite(dirPin,LOW); //If value is I then set dir low and Step low digitalWrite(stepPin,LOW); } } } else if(Incoming_value == '9') //Checks whether value of Incoming_value is equal to 1 { digitalWrite(dirPin,LOW); // Enables the motor to move in a particular direction // Makes 200 pulses for making one full cycle rotation for(int x = 0; x < 1000; x++) { digitalWrite(stepPin,HIGH); delay(1); // ms digitalWrite(stepPin,LOW); delay(1); if(Incoming_value == 'I') //Checks whether value of Incoming_value is equal to 0 { digitalWrite(dirPin,LOW); //If value is I then set dir low and Step low digitalWrite(stepPin,LOW); } } } } }